import axios, { AxiosRequestConfig, Method } from 'axios'
import { VERSION, IGNORE_ERROR, FILTER_ERROR, NET_ERROR } from './const'
import { uris, baseUrl } from '~/api'

class HttpRequest {
  private uri: string //资源路由
  private requestData?: any

  constructor(uri: string, data?: any) {
    this.uri = uri
    this.requestData = data
  }

  public instance() {
    const ins = axios.create()
    const options = this.prepareOptions()

    return ins(options)
  }

  public request() {
    const ins = axios.create()
  }

  public prepareOptions(data?: any): AxiosRequestConfig {
    let option: AxiosRequestConfig = {
      url: '',
      data: null as any,
      method: 'GET' as Method,
      timeout: 60000,
      headers: {
        Authorization: cache.getToken() || '',
        'X-Requested-With': 'XMLHttpRequest',
        version: VERSION,
        Platform: 'telegram'
      }
    }
    return option
  }
}

export function getBaseUrl(): string {
  return import.meta.env.VITE_ENV === 'pro' ? baseUrl : localStorage.getItem('DEV_URL') || baseUrl
}
